using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Karasoft.Web.UI
{

    public class HijriDateField : BoundField
    {
      
        /// <summary>
        /// Builds the contents of the field
        /// </summary>
        protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState)
        {
            // If not editing, show in scrolling div
            if ((rowState & DataControlRowState.Edit) == 0)
            {
                HijriLabel oHijriLabel = new Karasoft.Web.UI.HijriLabel();
                oHijriLabel.DataBinding += new EventHandler(HijriLabel_DataBinding);
                cell.Controls.Add(oHijriLabel);
            }
            else
            {
                DateCombo oDateCombo = new Karasoft.Web.UI.DateCombo();
                oDateCombo.DataBinding += new EventHandler(DateCombo_DataBinding);
                cell.Controls.Add(oDateCombo);
            }
        }
        /// <summary>
        /// Called when databound in display mode
        /// </summary>
        void HijriLabel_DataBinding(object s, EventArgs e)
        {
            HijriLabel oHijriLabel = (HijriLabel)s;
            // Get the field value
            Object value = this.GetValue(oHijriLabel.NamingContainer);
            if (value != null)
                oHijriLabel.Date = DateTime.Parse(value.ToString());
            else
            {
                oHijriLabel.Visible = false;
            }
            // Assign the formatted value
          //  div.InnerText = this.FormatDataValue(value, this.HtmlEncode);
        }
        /// <summary>
        /// Called when databound in edit mode
        /// </summary>
        void DateCombo_DataBinding(object s, EventArgs e)
        {
            DateCombo oDateCombo = (DateCombo)s;
            // Get the field value
            Object value = this.GetValue(oDateCombo.NamingContainer);
            // Assign the formatted value
            if (value != null)
                oDateCombo.SelectedDate = DateTime.Parse(this.FormatDataValue(value, this.HtmlEncode));
        }
    }
}
